import java.io.IOException;
import java.net.SocketException;

import org.apache.commons.net.telnet.TelnetClient;


public class IncomingDataParser {
	
	public String CheckDeviceValidity(String Device)
	{
		if (Device.contentEquals("5600") || Device.contentEquals("2300") || Device.contentEquals("3528")) 
				//||
				//Device.contentEquals("5300") || Device.contentEquals("5105") || Device.contentEquals("5605") ||
				//Device.contentEquals("Honet")) 
				return "True";
		else return "Invalid device name: " + Device;
	}
	
	public String CheckCommandValidity(String Command)
	{
		if (Command.contentEquals("GetPortStatus") || Command.contentEquals("SetPortReset") || Command.contentEquals("GetPortPVC") ||
				Command.contentEquals("SetPortRateProfile")) return "True";
		else return "Invalid command: " + Command;
	}
	
	public String CheckIPValidity(String IP)
	{
		//10.56.156.27
		
		if (IP.startsWith("10.56."))
		{
			// Allocating buffer for second part of IP Address
			char[] SecondPartOfIPAddress = new char[7];
			
			int DotCounter = 0;
			
			try
			{
			// Extracting chars from incoming string to buffer
			IP.getChars(6, IP.length(), SecondPartOfIPAddress, 0);
			for (int i = 0; i < SecondPartOfIPAddress.length; i++) System.out.print("[" + SecondPartOfIPAddress[i] + "] ");
				for (int i = 0; i < SecondPartOfIPAddress.length; i++)
				{
					if (SecondPartOfIPAddress[i] == '.') DotCounter++; 
					if (SecondPartOfIPAddress[i] != '.' && !Character.isDefined(SecondPartOfIPAddress[i]) && SecondPartOfIPAddress[i] != ' ' && ! Character.isDigit(SecondPartOfIPAddress[i]) ) return " IP adress is invalid or device is unreachable";
				}
//				Character.is
			}
			catch (Exception e)
			{
				e.printStackTrace();
				return " IP adress is invalid or device is unreachable";
			}
			return "True";
		}
		
		return " IP adress is invalid or device is unreachable";
	}
}
